<?php

namespace app\admin\controller;

use think\Controller;
use think\Request;
use think\Session;

class Main extends Controller
{

    public function _initialize()
    {

        if (empty(Session::get('admin_username'))){
            $this->redirect('admin/index/index');
        }

        //获得方法名，控制器名
        $request = Request::instance();
        $controller = $request->controller();
        $method = $request->action();
        //拼接控制器和方法
        $cm = $controller.$method;
        $cjoinm = Session::get('cjoinm');
        // dump($cjoinm);
        // dump($cm);die;
        if(Session::get('admin_username') != 'admin'){
            //验证操作权限
            if(empty($cjoinm) || !in_array($cm,$cjoinm)){

                // $this->error("没有操作权限");
                echo '<div style="font-size:50px;color:red;height:300px;width:300px;margin:100px auto;">没有操作权限</div>';die;
            }

        }
    }
}